home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- +
- + LEDA 2.1.1 11-15-1991
- +
- +
- + planar_map.h
- +
- +
- + Copyright (c) 1991 by Max-Planck-Institut fuer Informatik
- + Im Stadtwald, 6600 Saarbruecken, FRG
- + All rights reserved.
- +
- *******************************************************************************/
-
-
-
-
- #ifndef PLANAR_MAPH
- #define PLANAR_MAPH
-
- #include <LEDA/graph.h>
-
- class i_face;
-
- typedef i_face* face;
-
- class i_face {
-
- friend class planar_map;
-
- edge head; // first edge of face
- list_item loc; // location in F_list
- ent inf; // user defined information
-
- planar_map* g; // face of (*g)
-
-
- friend planar_map* graph_of(face f) { return f->g; }
-
-
- i_face(ent x, planar_map* G)
- {
- inf = x ;
- head = nil;
- loc = nil;
- g = G;
- }
-
-
- OPERATOR_NEW(4)
- OPERATOR_DEL(4)
-
- };
-
- declare(list,face);
-
- declare(node_array,int)
-
- class planar_map : public graph {
-
- list(face) F_list;
-
- face new_face(ent i=0);
- void del_face(face f) { F_list.del(f->loc); delete f; }
- face& get_face(edge e) { return (face&)(e->contents); }
- edge& get_rev(edge e) { return (edge&)(e->adj_loc2); }
-
- virtual void copy_face_entry(ent& x) const {x=x;}
- virtual void init_face_entry(ent& x) const {x=0;}
- virtual void clear_face_entry(ent& x) const {x=0;}
- virtual void print_face_entry(ent& x) const {x=x;}
-
- public:
-
-
- planar_map(const graph&);
- ~planar_map();
-
- void init_entries();
-
-
- list(node) adj_nodes(face) const;
- list(node) adj_nodes(node v) const { return graph::adj_nodes(v); }
-
- list(edge) adj_edges(face) const;
- list(edge) adj_edges(node v) const { return graph::adj_edges(v); }
-
- list(face) all_faces() const { return F_list; }
- list(face) adj_faces(node) const;
-
- face adj_face(edge e) const { return face(e->contents); }
-
- list(edge) triangulate();
-
- edge reverse(edge e) const { return edge(e->adj_loc2); }
-
- edge first_face_edge(face f) const { return f->head; }
- edge succ_face_edge(edge e) const { return cyclic_adj_succ(reverse(e)); }
- edge pred_face_edge(edge e) const { return reverse(cyclic_adj_pred(e)); }
-
- edge next_face_edge(edge e) const
- { e = succ_face_edge(e);
- return (e==adj_face(e)->head) ? nil : e;
- }
-
- face first_face() const { return F_list.head(); }
-
- face next_face(face f) const
- { list_item it = F_list.succ(f->loc);
- return (it) ? F_list.contents(it) : nil;
- }
-
-
- edge new_edge(edge,edge,ent=0);
- void del_edge(edge,ent=0);
-
- ent& entry(face f) { return f->inf; }
- ent inf(face f) const { return f->inf; }
- ent& entry(node v) { return graph::entry(v); }
- ent inf(node v) const { return graph::inf(v); }
-
- int straight_line_embedding(node_array(int)&, node_array(int)&);
-
- };
-
-
- //------------------------------------------------------------------------------
- // PLANAR_MAP: generic planar map
- //------------------------------------------------------------------------------
-
- #define PLANAR_MAP(vtype,ftype) name3(vtype,ftype,PLANAR_MAP)
-
- #define PLANAR_MAPdeclare2(vtype,ftype)\
- \
- class PLANAR_MAP(vtype,ftype) : public planar_map {\
- \
- void init_node_entry(ent& x) const { vtype y=0; x = Copy(y); }\
- void init_face_entry(ent& x) const { ftype y=0; x = Copy(y); }\
- \
- void copy_node_entry(ent& x) const { Copy(*(vtype*)&x); }\
- void copy_face_entry(ent& x) const { Copy(*(ftype*)&x); }\
- \
- void clear_node_entry(ent& x) const { Clear(*(vtype*)&x); }\
- void clear_face_entry(ent& x) const { Clear(*(ftype*)&x); }\
- \
- public:\
- \
- vtype inf(node v) const { return vtype(planar_map::inf(v)); }\
- ftype inf(face f) const { return ftype(planar_map::inf(f)); }\
- vtype& entry(node v) { return *(vtype*)&(planar_map::entry(v)); }\
- ftype& entry(face f) { return *(ftype*)&(planar_map::entry(f)); }\
- vtype& operator[] (node v) { return entry(v); }\
- ftype& operator[] (face f) { return entry(f); }\
- \
- edge new_edge(edge e1, edge e2)\
- { return planar_map::new_edge(e1,e2,0); }\
- edge new_edge(edge e1, edge e2, ftype a)\
- { return planar_map::new_edge(e1,e2,Ent(a)); }\
- \
- void print_node(node v) const { cout << "["; Print((vtype&)(entry(v))); cout << "]";}\
- \
- PLANAR_MAP(vtype,ftype)(const GRAPH(vtype,ftype)& G) : ((graph&)G) {}\
- ~PLANAR_MAP(vtype,ftype)() { clear(); }\
- \
- };
-
-
- #define forall_face_edges(e,F)\
- for(e=graph_of(F)->first_face_edge(F); e; e=graph_of(F)->next_face_edge(e))
-
- #define forall_faces(f,G)\
- for(f=G.first_face(); f; f=G.next_face(f))
-
-
-
- #endif PLANAR_MAPH
-